import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routerPush = Router.prototype.push
Router.prototype.push = function push (location) {
    return routerPush.call(this, location).catch(error => error)
}

// 全屏页面与管理后台页面用 meta.fullscreen 控制
const routerList = [
    {
        path: '/',
        redirect: { name: 'dashboard' }
    },
    // 全屏页面
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue'),
        meta: { title: '登陆', fullscreen: true }
    },
    // 管理后台页面
    {
        path: '/dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: '控制台' }
    },
    {
        path: '/user/info',
        name: 'user.info',
        component: () => import('@/views/user/info.vue'),
        meta: { title: '个人资料' }
    },
    {
        path: '/user/password',
        name: 'user.password',
        component: () => import('@/views/user/password.vue'),
        meta: { title: '修改密码' }
    },
    {
        path: '/demo',
        name: 'demo',
        component: () => import('@/views/demo/index.vue'),
        meta: { title: '示例页面' }
    },
    {
        path: '/403',
        name: '403',
        component: () => import('@/views/errors/403.vue'),
        meta: { title: '访问受限' }
    },
    {
        path: '/404',
        name: '404',
        component: () => import('@/views/errors/404.vue'),
        meta: { title: '页面不存在' }
    },
    {
        path: '/:pathMatch(.*)*',
        redirect: { name: '404' }
    }
]

const router = new Router({
    routes: routerList
})

export { router }
